import {
  requestUtil
} from "../../utils/requestUtil";
// pages/catagory/index.js
Page({


  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: 0,
    parentList: [],
    chirldrenList: [],
    categoryList: []
  },
  cates: [],
  // 左侧菜单的点击事件 
  handleMenuItemChange(e) {
    const {index} = e.currentTarget.dataset;
    let chirldrenList = this.Cates[index].childrenCategory;
    this.setData({
      currentIndex: index,
      chirldrenList
    })
  },


  onLoad(options) {
    requestUtil({
        url: '/category/getCategoryList',
        method: 'GET'
      }).then(result => {
        console.log(result);
        this.setData({
          categoryList: result.data,
        })
      }),
      requestUtil({
        url: '/category/getCategoryList',
        method: "GET"
      }).then(res => {
        console.log(res);
        this.Cates = res.data;
        let parentList = this.Cates.map(v => v.parentName);
        let chirldrenList = this.Cates[0].childrenCategory;
        this.setData({
          parentList,
          chirldrenList
        })

      });

  },


  async getCates() {
    const result = await requestUtil({
      url: '/category/getCategoryList',
      method: "GET"
    });
    this.Cates = result.message;
    let parentList = this.Cates.map(v => v.name);
    let chirldrenList = this.Cates[0].smallTypeList;
    this.setData({
      parentList,
      chirldrenList
    })
  },



})